#include "imageProcess.hpp"

#define Height 800
#define Width 1280
#define SegmentWidth 160
#define SegmentHeight 100

#pragma pack(push, 8) // 设置结构体按8字节对齐
static uchar frame_buffer[800 * 1280 * 4];
static uchar frame_buffer_copy[800 * 1280 * 4];
static uchar frame_buffer_old[800 * 1280 * 4];
#pragma pack(pop) // 恢复默认对齐方式

static std::vector<uchar> jpg_image;

int main()
{
    auto start = std::chrono::high_resolution_clock::now();

    // auto result = compareAndCopy(frame_buffer_copy, frame_buffer_old, sizeof(frame_buffer_old) / 4);
    memcopy(frame_buffer_copy, frame_buffer_old, sizeof(frame_buffer_old));

    auto end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double, std::milli> elapsed = end - start;
    std::cout << "memcopy Elapsed time: " << elapsed.count() << " ms\n";

    auto _start = std::chrono::high_resolution_clock::now();

    // auto result = compareAndCopy(frame_buffer_copy, frame_buffer_old, sizeof(frame_buffer_old) / 4);
    // memcpy(frame_buffer_copy, frame_buffer_old, sizeof(frame_buffer_old));

    // // 定义矩形区域 (x, y, width, height) 截取图像
    // cv::Mat image(Height, Width, CV_8UC4, (char *)frame_buffer);
    // cv::Rect roi(0, 0, 160, 120);
    // cv::Mat cropped_image = image(roi);

    imageBlockingCompareAndCopy(frame_buffer, frame_buffer_copy, Width, Height, SegmentWidth, SegmentHeight);

    auto _end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double, std::milli> _elapsed = _end - _start;
    std::cout << "memcpy Elapsed time: " << _elapsed.count() << " ms\n";

    return 0;
}